<template>
  <span>
    {{ countValue }}
  </span>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import Lib from '../../lib'
const props = defineProps({
  code: {
    require: true,
    type: String,
    default: '',
  },
})
const countValue = ref(0)

onMounted(async () => {
  const dbName = `proj_${props.code}`
  const cgtToken = await Lib.CGT.getToken()
  if (!cgtToken) return
  const cgtIsHasDB = await Lib.CGT.hasDatabase(cgtToken, dbName)
  if (!cgtIsHasDB) {
    countValue.value = 0
  } else {
    countValue.value = await Lib.CGT.getCountByModule(cgtToken, dbName, Lib.CGT.module.asset)
  }
})
</script>
